home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_061 / microemacs / egapc.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  7KB  |  346 lines

  1. /*
  2.  * The routines in this file provide support for the IBM-PC EGA and other
  3.  * compatible terminals. It goes directly to the graphics RAM to do
  4.  * screen output. It compiles into nothing if not an IBM-PC EGA driver
  5.  */
  6.  
  7. #define    termdef    1            /* don't define "term" external */
  8.  
  9. #include        <stdio.h>
  10. #include    "estruct.h"
  11. #include        "edef.h"
  12.  
  13. #if     EGA
  14.  
  15. #define NROW    43                      /* Screen size.                 */
  16. #define NCOL    80                      /* Edit if you want to.         */
  17. #define    MARGIN    8            /* size of minimim margin and    */
  18. #define    SCRSIZ    64            /* scroll size for extended lines */
  19. #define    NPAUSE    200            /* # times thru update to pause */
  20. #define BEL     0x07                    /* BEL character.               */
  21. #define ESC     0x1B                    /* ESC character.               */
  22. #define    SPACE    32            /* space character        */
  23. #define    SCADD    0xb8000000L        /* address of screen RAM    */
  24.  
  25. int *scptr[NROW];            /* pointer to screen lines    */
  26. int sline[NCOL];            /* screen line image        */
  27.  
  28. extern  int     ttopen();               /* Forward references.          */
  29. extern  int     ttgetc();
  30. extern  int     ttputc();
  31. extern  int     ttflush();
  32. extern  int     ttclose();
  33. extern    int    egakopen();
  34. extern    int    egakclose();
  35. extern  int     egamove();
  36. extern  int     egaeeol();
  37. extern  int     egaeeop();
  38. extern  int     egabeep();
  39. extern  int     egaopen();
  40. extern    int    egarev();
  41. extern    int    egacres();
  42. extern    int    egaclose();
  43. extern    int    egaputc();
  44.  
  45. #if    COLOR
  46. extern    int    egafcol();
  47. extern    int    egabcol();
  48.  
  49. int    cfcolor = -1;        /* current forground color */
  50. int    cbcolor = -1;        /* current background color */
  51. int    ctrans[] =        /* ansi to ega color translation table */
  52.     {0, 4, 2, 6, 1, 5, 3, 7};
  53. #endif
  54.  
  55. /*
  56.  * Standard terminal interface dispatch table. Most of the fields point into
  57.  * "termio" code.
  58.  */
  59. TERM    term    = {
  60.     NROW-1,
  61.         NROW-1,
  62.         NCOL,
  63.         NCOL,
  64.     MARGIN,
  65.     SCRSIZ,
  66.     NPAUSE,
  67.         egaopen,
  68.         egaclose,
  69.     egakopen,
  70.     egakclose,
  71.         ttgetc,
  72.     egaputc,
  73.         ttflush,
  74.         egamove,
  75.         egaeeol,
  76.         egaeeop,
  77.         egabeep,
  78.     egarev,
  79.     egacres
  80. #if    COLOR
  81.     , egafcol,
  82.     egabcol
  83. #endif
  84. };
  85.  
  86. extern union REGS rg;
  87.  
  88. #if    COLOR
  89. egafcol(color)        /* set the current output color */
  90.  
  91. int color;    /* color to set */
  92.  
  93. {
  94.     cfcolor = ctrans[color];
  95. }
  96.  
  97. egabcol(color)        /* set the current background color */
  98.  
  99. int color;    /* color to set */
  100.  
  101. {
  102.         cbcolor = ctrans[color];
  103. }
  104. #endif
  105.  
  106. egamove(row, col)
  107. {
  108.     rg.h.ah = 2;        /* set cursor position function code */
  109.     rg.h.dl = col;
  110.     rg.h.dh = row;
  111.     rg.h.bh = 0;        /* set screen page number */
  112.     int86(0x10, &rg, &rg);
  113. }
  114.  
  115. egaeeol()    /* erase to the end of the line */
  116.  
  117. {
  118.     int attr;    /* attribute byte mask to place in RAM */
  119.     int *lnptr;    /* pointer to the destination line */
  120.     int i;
  121.     int ccol;    /* current column cursor lives */
  122.     int crow;    /*       row    */
  123.  
  124.     /* find the current cursor position */
  125.     rg.h.ah = 3;        /* read cursor position function code */
  126.     rg.h.bh = 0;        /* current video page */
  127.     int86(0x10, &rg, &rg);
  128.     ccol = rg.h.dl;        /* record current column */
  129.     crow = rg.h.dh;        /* and row */
  130.  
  131.     /* build the attribute byte and setup the screen pointer */
  132. #if    COLOR
  133.     attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8;
  134. #else
  135.     attr = 0x0700;
  136. #endif
  137.     lnptr = &sline[0];
  138.     for (i=0; i < NCOL; i++)
  139.         *lnptr++ = SPACE | attr;
  140.  
  141.     if (flickcode) {
  142.         /* wait for vertical retrace to be off */
  143.         while ((inp(0x3da) & 8))
  144.             ;
  145.  
  146.         /* and to be back on */
  147.         while ((inp(0x3da) & 8) == 0)
  148.             ;
  149.     }
  150.  
  151.     /* and send the string out */
  152.     movmem(&sline[0], scptr[crow]+ccol, (NCOL-ccol)*2);
  153.  
  154. }
  155.  
  156. egaputc(ch)    /* put a character at the current position in the
  157.            current colors */
  158.  
  159. int ch;
  160.  
  161. {
  162.     rg.h.ah = 14;        /* write char to screen with current attrs */
  163.     rg.h.al = ch;
  164. #if    COLOR
  165.     rg.h.bl = cfcolor;
  166. #else
  167.     rg.h.bl = 0x07;
  168. #endif
  169.     int86(0x10, &rg, &rg);
  170. }
  171.  
  172. egaeeop()
  173. {
  174.     int attr;        /* attribute to fill screen with */
  175.  
  176.     rg.h.ah = 6;        /* scroll page up function code */
  177.     rg.h.al = 0;        /* # lines to scroll (clear it) */
  178.     rg.x.cx = 0;        /* upper left corner of scroll */
  179.     rg.x.dx = 0x2a4f;    /* lower right corner of scroll */
  180. #if    COLOR
  181.     attr = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  182. #else
  183.     attr = 0;
  184. #endif
  185.     rg.h.bh = attr;
  186.     int86(0x10, &rg, &rg);
  187. }
  188.  
  189. egarev(state)        /* change reverse video state */
  190.  
  191. int state;    /* TRUE = reverse, FALSE = normal */
  192.  
  193. {
  194.     /* This never gets used under the ega-PC driver */
  195. }
  196.  
  197. egacres()    /* change screen resolution */
  198.  
  199. {
  200.     return(TRUE);
  201. }
  202.  
  203. egabeep()
  204. {
  205.     bdos(6, BEL, 0);
  206. }
  207.  
  208. egaopen()
  209. {
  210.     char buf;    /* buffer for peek/poke */
  211.  
  212.     /* initialize pointers to the screen ram */
  213.     scinit();
  214.  
  215.     /* and put the beast into EGA 43 row mode */
  216.     rg.x.ax = 3;
  217.     int86(0x10, &rg, &rg);
  218.  
  219.     rg.x.ax = 0x1112;
  220.     rg.h.bl = 0;
  221.     int86(0x10, &rg, &rg);
  222.  
  223.     peek(0x40, 0x87, &buf, 1);
  224.     buf |= 1;
  225.     poke(0x40, 0x87, &buf, 1);
  226.     buf = 0xf8;
  227.     poke(0x40, 0x88, &buf, 1);
  228.  
  229.     rg.x.ax = 0x0100;
  230.     rg.h.bh = 0;
  231.     rg.x.cx = 0x0007;
  232.     int86(0x10, &rg, &rg);
  233.  
  234.     buf = 0xf9;
  235.     poke(0x40, 0x88, &buf, 1);
  236.  
  237.     strcpy(sres, "43LINE");
  238.     revexist = TRUE;
  239.         ttopen();
  240. }
  241.  
  242. egaclose()
  243.  
  244. {
  245.     char buf;    /* buffer for peek/poke */
  246.  
  247. #if    COLOR
  248.     egafcol(7);
  249.     egabcol(0);
  250. #endif
  251.     /* and put the beast into 80 column mode */
  252.     rg.x.ax = 0002;
  253.     int86(0x10, &rg, &rg);
  254.     ttclose();
  255.  
  256. #if    0
  257.     peek(0x40, 0x87, &buf, 1);
  258.     buf--;
  259.     poke(0x40, 0x87, &buf, 1);
  260. #endif
  261.  
  262.     /* and restore the normal cursor */
  263.     rg.x.ax = 0x0100;
  264.     rg.h.bl = 0;
  265.     rg.x.cx = 0x0b0d;
  266.     int86(0x10, &rg, &rg);
  267. }
  268.  
  269. egakopen()
  270.  
  271. {
  272. }
  273.  
  274. egakclose()
  275.  
  276. {
  277. }
  278.  
  279. scinit()    /* initialize the screen head pointers */
  280.  
  281. {
  282.     union {
  283.         long laddr;    /* long form of address */
  284.         int *paddr;    /* pointer form of address */
  285.     } addr;
  286.     int i;
  287.  
  288.     /* initialize the screen pointer array */
  289.     for (i = 0; i < NROW; i++) {
  290.         addr.laddr = SCADD + (long)(NCOL * i * 2);
  291.         scptr[i] = addr.paddr;
  292.     }
  293. }
  294.  
  295. scwrite(row, outstr, forg, bacg)    /* write a line out*/
  296.  
  297. int row;    /* row of screen to place outstr on */
  298. char *outstr;    /* string to write out (must be NCOL long) */
  299. int forg;    /* forground color of string to write */
  300. int bacg;    /* background color */
  301.  
  302. {
  303.     int attr;    /* attribute byte mask to place in RAM */
  304.     int *lnptr;    /* pointer to the destination line */
  305.     int i;
  306.  
  307.     /* build the attribute byte and setup the screen pointer */
  308. #if    COLOR
  309.     attr = (((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) << 8;
  310. #else
  311.     attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  312. #endif
  313.     lnptr = &sline[0];
  314.     for (i=0; i<term.t_ncol; i++)
  315.         *lnptr++ = (outstr[i] & 255) | attr;
  316.  
  317.     if (flickcode) {
  318.         /* wait for vertical retrace to be off */
  319.         while ((inp(0x3da) & 8))
  320.             ;
  321.  
  322.         /* and to be back on */
  323.         while ((inp(0x3da) & 8) == 0)
  324.             ;
  325.     }
  326.  
  327.     /* and send the string out */
  328.     movmem(&sline[0], scptr[row],term.t_ncol*2);
  329. }
  330.  
  331. #if    FLABEL
  332. fnclabel(f, n)        /* label a function key */
  333.  
  334. int f,n;    /* default flag, numeric argument [unused] */
  335.  
  336. {
  337.     /* on machines with no function keys...don't bother */
  338.     return(TRUE);
  339. }
  340. #endif
  341. #else
  342. egahello()
  343. {
  344. }
  345. #endif
  346.